****TABLE 4****

cd "$main_dir/output/tables/main"

*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************
*PANEL A - UNITED STATES (ANES)**************************************************************************************************************************************
*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize_var
program define standardize_var
	
	args var
	
	cap drop z*
	local varlist trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table 4 (Panel A)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 winflation_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize_var winflation_1
reghdfe ztrust_fed_govt zwgrowth_rate_1 zwinflation_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_4_panel_a.doc, replace dec(3) nocons keep(zwgrowth_rate_1 zwinflation_1) 

//Column 2-5
local varlist wsp500return_1 wpretax_income_top10_1 wpretax_income_top1_1 wunemployment_rate_1
foreach var of local varlist {
	qui reghdfe trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt zwgrowth_rate_1 z`var' zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	outreg2 using table_4_panel_a.doc, append dec(3) nocons keep(zwgrowth_rate_1 z`var') 														
}


******************************************************************************************************************************************************************
******************************************************************************************************************************************************************
*PANEL B - SWITZERLAND (SHP)**************************************************************************************************************************************
******************************************************************************************************************************************************************
******************************************************************************************************************************************************************

global basic 	marital edu
global econ	    employment_status occupation income imputed_income
global design 	survey_year age language
global polit    ideology party_member

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize_var
program define standardize_var
	
	args var
	
	cap drop z*
	local varlist trust_fed_govt_med wgrowth_rate_1 `var'
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/shp_final_panel.dta"

xtset idpers survey_year

gen dummy = 1 if trust_fed_govt_med!=.
bys idpers: egen total_obs = total(dummy)

cap drop sample
gen sample = 1 if live_switz==1 & total_obs>4 & total_obs!=. & age>=15 & age!=.

egen canton_survey_year = group(canton survey_year)

//--------------------------------------------------------
//Create Table 4 (Panel B)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt_med wgrowth_rate_1 winflation_1 if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
standardize_var winflation_1
reghdfe ztrust_fed_govt_med zwgrowth_rate_1 zwinflation_1 if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
outreg2 using table_4_panel_b.doc, replace dec(3) nocons keep(zwgrowth_rate_1 zwinflation_1)  														 

//Column 2-5														   
local varlist wstock_return_1 wpretax_income_top10_1 wpretax_income_top1_1 wunemployment_rate_1
foreach var of local varlist {
	qui reghdfe trust_fed_govt_med wgrowth_rate_1 `var' if sample==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
	standardize_var `var'
	reghdfe ztrust_fed_govt_med zwgrowth_rate_1 z`var' if e(sample)==1, absorb(canton $basic $design $econ $polit idpers) cluster(idhous yob)
	outreg2 using table_4_panel_b.doc, append dec(3) nocons keep(zwgrowth_rate_1 z`var') 
													
}
